﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc;
using System.Web.Security;
using System.Web.UI.WebControls;
using System.Collections;
using System.Linq;

namespace ElectronicDiary.Models.Admin
{
    public class StudentEditAddModel
    {
        public int ID { get; set; }

        [Required(ErrorMessage = "{0} jest wymagany.")]
        [Display(Name = "Rodzic")]
        public int IDParent { get; set; }

        [Required(ErrorMessage = "{0} jest wymagana.")]
        [Display(Name = "Klasa")]
        public int IDClass { get; set; }

        [Required(ErrorMessage = "{0} jest wymagane.")]
        [Display(Name = "Imię")]
        public string FName { get; set; }

        [Required(ErrorMessage = "{0} jest wymagane.")]
        [Display(Name = "Nazwisko")]
        public string LName { get; set; }

        [Required(ErrorMessage = "{0} jest wymagana.")]
        [Display(Name = "Data urodzenia")]
        [DataType(DataType.Date)]
        public DateTime BirthDate { get; set; }

        [Required(ErrorMessage = "{0} jest wymagane.")]
        [Display(Name = "Miasto")]
        public string City { get; set; }

        [Required(ErrorMessage = "{0} jest wymagane.")]
        [Display(Name = "Kod pocztowy")]
        public string ZipCode { get; set; }

        [Required(ErrorMessage = "{0} jest wymagana.")]
        [Display(Name = "Ulica")]
        public string StreetName { get; set; }

        [Required(ErrorMessage = "{0} jest wymagany.")]
        [Display(Name = "Numer")]
        public string Number { get; set; }

        [Display(Name = "Aktywny")]
        public bool Active { get; set; }

        public IEnumerable<SelectListItem> Parents
        {
            get
            {
                using (var context = new electronicDiaryEntities())
                {
                    var collection = context.parent.ToDictionary(n => n.idParent , n => n.lastName + " " + n.firstName);
                    IEnumerable<SelectListItem> sli;
                    sli = collection.Select(n => new SelectListItem
                    {
                        Value = n.Key.ToString(),
                        Text = n.Value
                    }).OrderBy(n => n.Text);
                    return sli;
                }
            }
        }

        public IEnumerable<SelectListItem> Classes
        {
            get
            {
                using (var context = new electronicDiaryEntities())
                {
                    var collection = context.@class.ToDictionary(n => n.idClass, n => n.Name);
                    IEnumerable<SelectListItem> sli;
                    sli = collection.Select(n => new SelectListItem
                    {
                        Value = n.Key.ToString(),
                        Text = n.Value
                    }).OrderBy(n => n.Text);
                    return sli;
                }
            }
        }
    }
}